package com.jackrain.nea.fc.cp.adutils;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import static java.lang.Thread.currentThread;

//import org.apache.commons.lang.StringUtils;

//import org.apache.log4j.Logger;
@Slf4j
public class ApplicationConstants {

    private static final String CONFIG_FILE = "config/rainconf.properties";
    private static Map<String, Object> configs = new HashMap<String, Object>();


//    private static final Logger log = Logger.getLogger(ApplicationConstants.class);
    static {
        InputStream in = null;
        Properties p = new Properties();
        try{
            in = currentThread().getContextClassLoader().getResourceAsStream(CONFIG_FILE);
            p.load(in);
            for(Object k : p.keySet()){
                String key = (String) k;
                configs.put( key, p.getProperty(key));
            }
            log.info("config.properties is loaded!"  );
        } catch (IOException e){
            log.error("Unable to read config.properties");
        } finally{
            if(in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    log.error("Unable to close inputstream");
                }
            }
        }
    }

    public static String getProperty(String key){
        return (String) configs.get(key);
    }


}